#include <iostream>
struct Base
{
    // 多态删除，基类析构必须虚
    // 写了这一行才会让 [delete b] 去实际调用子类的析构函数
    virtual ~Base() = default;
    // 1、如果不写这一行[delete b] 会按照基类处理，引发内存泄露
};
struct Derived : Base
{
private:
    char *p;

public:
    Derived(unsigned size)
    {
        p = new char[size];
        std::cout << "ctor called" << std::endl;
    }
    ~Derived()
    {
        delete[] p;
        std::cout << "dtor called" << std::endl;
    }
};

int main()
{
    Base *b{nullptr};
    b = new Derived(16);
    delete b;
}
